home *** CD-ROM | disk | FTP | other *** search
- title "QUICKSORT (x,lo,hi)"
- "**********************************************
- * Purpose: *
- * Sorts the elements of array x that *
- * are between the lo and hi indices *
- * Input: *
- * x an array (sorted or unsorted) *
- * lo low index *
- * hi high index *
- * Output: *
- * x sorted in ascending order *
- **********************************************"
- if "if lo < hi" then "then" :
- "pivot_value := x[lo]"
- "pivot_index := lo"
- for "for i := (lo+1) to hi" do
- if "if╩x[i]╩<╩pivot_value" then "then" :
- "increment pivot_index"
- "swap x[i] and x[pivot_index]"
- endif
- endfor
- "swap x[pivot_index] and x[lo]"
- call "call quicksort(x,lo,pivot_index-1)"
- call "call quicksort(x,pivot_index+1,hi)"
- endif
-